package com.mall.gateway.filters;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.lang.annotation.Annotation;

@Component
//@Order(-1)
public class AuthorizeFilter implements GlobalFilter,Order {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        //1.获取请求参数
        MultiValueMap<String, String> params = exchange.getRequest().getQueryParams();
        //2.获取authorizetion
        String authorization = params.getFirst("authorization");

        //3.校验
        return chain.filter(exchange);

        //5.不放行，添加响应状态
//        exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
//        //6.不放行，结束
//        return exchange.getResponse().setComplete();
    }

    @Override
    public int value() {
        return -1;
    }

    @Override
    public Class<? extends Annotation> annotationType() {
        return null;
    }
}
